package com.xdwanj.smartcity.data.repository;

import android.content.Context;
import android.content.SharedPreferences;

import androidx.lifecycle.LiveData;
import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.xdwanj.smartcity.App;
import com.xdwanj.smartcity.data.bean.User;
import com.xdwanj.smartcity.data.config.Configs;
import com.xdwanj.smartcity.data.repository.impl.UserRepository;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(AndroidJUnit4.class)
public class IUserRepositoryTest {

    private static final String TAG = "IUserRepositoryTest";
    private UserRepository repository;
    private SharedPreferences sp;
    private Context context;

    @Before
    public void setUp() throws Exception {
        context = App.context;
        repository = UserRepository.getInstance();
        sp = App.sp;
    }

    @Test
    public void login() throws Exception {
        LiveData<String> xdwanj = repository.login("xdwanj", "123456");
        Thread.sleep(500);
        System.out.println("xdwanj.getValue() = " + xdwanj.getValue());
    }

    @Test
    public void register() throws Exception {
        LiveData<Boolean> register = repository.register(
                ((int) (Math.random() * 10000)) + "",
                ((int) (Math.random() * 10000)) + "",
                ((int) (Math.random() * 10000)) + "123123",
                0
        );
        Thread.sleep(500);
        System.out.println("register.getValue() = " + register.getValue());
    }

    @Test
    public void cancelByTag() {
    }

    @Test
    public void getUser() throws Exception {
        LiveData<User> user = repository.getUser();
        Thread.sleep(500);
        System.out.println("user.getValue() = " + App.gson.toJson(user.getValue()));
    }

    @Test
    public void test() throws Exception {
    }

    @Test
    public void saveDiskToken() throws Exception {
    }

    @Test
    public void getDiskToken() throws Exception {
        System.out.println("Configs.TOKEN = " + Configs.TOKEN);
        String diskToken = repository.getDiskToken();
        System.out.println("diskToken = " + diskToken);
    }

}